/**
 * @file  搜索接口配置文件
 * */

import { request } from '@/shared/axios';
import type { SearchParamsT, SearchResultT } from '@/@types/type-search';
import type { LocaleT } from '@/@types/type-common';

/**
 * 关键字搜索结果
 * @param {SearchParamsT} params
 */
export const searchDocsApi = async (
  params: SearchParamsT
): Promise<{
  records: SearchResultT[];
  count: number;
  pageSize: number;
  page: number;
  keyword: string;
}> => {
  const res = await request.post('/api-search/search/docs', params, {
    headers: {
      source: 'ubmc',
    },
  });
  return res.data?.obj || {};
};

/**
 * 根据关键字动态搜索关联词
 * @param {string} query
 * @param {LocaleT} lang
 */
export const getSearchWordApi = async (query: string, lang: LocaleT) => {
  const res = await request.post(
    '/api-search/search/word',
    { query, lang },
    {
      headers: {
        source: 'ubmc',
      },
    }
  );
  return res?.data?.obj?.word || [];
};

/**
 * 获取热门搜索
 */
export const getHotSearchApi = async (): Promise<string[]> => {
  return ['组件新增', '板卡适配', '接口映射配置', 'BMCStudio', 'CSR'];
};
